package analysis.ProfessionalBottom10;

import analysis.Profess;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;

public class ProfessionalBottom10Reducer extends Reducer<IntWritable, Profess, Profess, NullWritable> {
    @Override
    protected void reduce(IntWritable key, Iterable<Profess> value, Context context) throws IOException, InterruptedException {
        ArrayList<Profess> list = new ArrayList<Profess>();
        for (Profess profess : value) {
            Profess o = new Profess(profess.getProfessName(), profess.getNumber());
            list.add(o);
        }
        Collections.sort(list);
        for (int i = list.size() - 1; i > list.size() - 11; i--) {
            context.write(list.get(i), NullWritable.get());
        }
    }
}